home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / gus / gmsrc211.zip / SD.ASM < prev    next >
Assembly Source File  |  1994-03-08  |  4KB  |  183 lines

  1. ;─────────────────────────────────────────────────────────────────────Decode────
  2. N       = 4096                  ; size of ring buffer
  3. F    = 18            ; upper limit for match_length
  4. THRESHOLD = 2            ; encode string into position and length
  5.                 ; if match_length is greater than this
  6.  
  7. flags    dw    0
  8. textbuf dw    0
  9.  
  10. ; bx - Handle
  11. ; cx - Num Bytes Long
  12. ; es:di - output
  13. textsize    dd    0
  14. codesize    dd    0
  15.  
  16. proc        GetDecodeSizes
  17.         push    ds bx
  18.         mov    ax,cs
  19.                 mov     ds,ax
  20.                 mov     ah,3Fh
  21.         mov    cx,8
  22.         mov    dx,offset textsize
  23.         int    21h
  24.         mov    si,[Word cs:textsize+2]
  25.         mov    di,[Word cs:textsize]
  26.         mov    dx,[Word cs:codesize+2]
  27.         mov    cx,[Word cs:codesize]
  28.         pop    bx ds
  29.         ret
  30. endp            GetDecodeSizes
  31.  
  32. proc        Decode
  33.         push    ds
  34.         mov    dx,[cs:TopOfData]
  35.         mov    [cs:textbuf],dx
  36.         add    dx,(N+F-1)/4+1
  37.  
  38.         mov    ds,dx        ; Load buffer
  39.         mov    dx,0
  40.         mov    ah,3Fh
  41.         int    21h
  42.         mov    si,0
  43.  
  44.         push    cx es
  45. ;               for (i = 0;i < N - F;i++) text_buf[i] = ' ';
  46.         mov    di,0
  47.         mov    ax,[cs:textbuf]
  48.         mov    es,ax
  49.         mov    cx,N-F
  50.         mov    al,' '
  51.         rep    stosb
  52.         pop    es cx
  53.         mov    di,0
  54.  
  55. ;        r = N - F; flags = 0;
  56.                 mov     [Word cs:flags],0
  57. ;         mov     [Word cs:r],N-F
  58.         mov    bx,N-F        ; R
  59. ;  for (;;)
  60. ;  {
  61. ;        if (((flags >>= 1) & 256) == 0)
  62. @@DecodeLoop:   shr     [Word cs:flags],1
  63.         mov    ax,[Word cs:flags]
  64.         and    ax,256
  65.         jnz    @@NextFlagCheck
  66.  
  67. ;        {
  68. ;          if ((c = getc(in)) == EOF) break;
  69.         lodsb
  70.         cmp    si,cx
  71.         jnb    @@Finish
  72. ;          flags = c | 0xff00;     /* uses higher byte cleverly to count eight */
  73.                 or      ah,0ffh
  74.         mov    [Word cs:flags],ax
  75. ;        }
  76. ;        if (flags & 1)
  77. @@NextFlagCheck:mov    ax,[cs:flags]
  78.         and    ax,1
  79.         jz    @@FlagCh2
  80. ;        {
  81. ;          if ((c = getc(in)) == EOF) break;
  82.         lodsb
  83.         cmp    si,cx
  84.         jg    @@Finish
  85. ;          putc(c, out); text_buf[r++] = c; r &= (N - 1);
  86.                 stosb
  87.         push    es
  88.         mov    es,[cs:textbuf]
  89.         mov    [es:bx],al
  90.         inc    bx
  91.         pop    es
  92.         and    bx,N-1
  93.         jmp    @@DecodeLoop
  94. ;        }
  95. ;        else
  96. ;        {
  97. ;          if ((i = getc(in)) == EOF) break;
  98. @@FlagCh2:    xor    ah,ah
  99.         lodsb
  100.         cmp    si,cx
  101.         jg    @@Finish
  102.                 mov     dx,ax                           ; i = DX
  103. ;          if ((j = getc(in)) == EOF) break;
  104.         lodsb                    ; j = AX
  105.         cmp    si,cx
  106.         jg    @@Finish
  107. ;                 i |= ((j & 0xf0) << 4);
  108.         push    ax
  109.         and    ax,0f0h
  110.         shl    ax,4
  111.         or    dx,ax
  112.         pop    ax
  113. ;          j = (j & 0x0f) + THRESHOLD;
  114.         and    ax,0fh
  115.         add    ax,THRESHOLD
  116. ;          for (k = 0;k <= j;k++)
  117.         mov    bp,0            ; k
  118. @@kloop:
  119.         push    ax            ; Save j
  120. ;                 {
  121. ;          c = text_buf[(i + k) & (N - 1)];
  122.         push    es bx
  123.         mov    es,[cs:textbuf]
  124.         mov    bx,dx            ; i
  125.         add    bx,bp            ; +k
  126.         and    bx,N-1
  127.         mov    al,[es:bx]
  128.         pop    bx es
  129. ;          putc(c, out);
  130.                 stosb
  131. ;          text_buf[r++] = c; r &= (N - 1);
  132.         push    es
  133.         mov    es,[cs:textbuf]
  134.         mov    [es:bx],al
  135.         inc    bx
  136.         pop    es
  137.                 and     bx,N-1
  138.         inc    bp            ; k++
  139.         pop    ax
  140.         cmp    bp,ax            ; k<=j
  141.         jle    @@kloop
  142.         jmp    @@DecodeLoop
  143. @@Finish:    pop    ds
  144.         ret
  145. endp            Decode
  146.  
  147. ;─────────────────────────────────────────────────────────────────────Decode────
  148. SoundFile:    db    'MUSIC210.INF',0,0,0
  149. ; CX:DX - Sound Driver Filename
  150. SoundHandle     dw      0
  151. proc        LoadSoundDriver
  152.         push    ds
  153.         push    ds
  154.         mov    ds,cx
  155.         mov    ax,3D00h
  156.         int    21h
  157.         jb    @@NoFind
  158.         pop    ds
  159.         mov    [cs:SoundHandle],ax
  160.         mov    bx,ax
  161.         call    GetDecodeSizes
  162.         mov    bx,di
  163.         shr    bx,4
  164.         inc    bx
  165.         mov    ax,[cs:TopOfData]
  166.         mov    [Word cs:Music+2],ax
  167.         add    [cs:TopOfData],bx
  168.         mov    es,ax
  169.         mov    di,0
  170.         mov    bx,[cs:SoundHandle]
  171.         call    Decode
  172.         mov    bx,[cs:SoundHandle]
  173.         mov    ah,3Eh
  174.         int    21h
  175.         pop    ds
  176.         clc
  177.         ret
  178. @@NoFind:    pop    ax ax
  179.         stc
  180.         ret
  181. endp            LoadSoundDriver
  182.  
  183.